using System;

namespace Nice157Advices.Advices
{
    /// <summary>
    /// 37、使用lambda表达式代替方法和匿名方法
    /// </summary>
    public static class _37
    {
        public static void Go ()
        {
            V1 ();
            V2 ();
            V3 ();
        }

        private static void V1 ()
        {
            Func<int, int, int> add = new Func<int, int, int> (Add);
            // Func<int, int, int> add = Add;
            Action<string> print = new Action<string> (Print);
            // Action<string> print = Print;
            print.Invoke (add (1, 2).ToString ());
        }

        private static void V2 ()
        {
            // Func<int, int, int> add = new Func<int, int, int> (delegate (int a, int b) { return a + b; });
            Func<int, int, int> add = delegate (int i, int j) { return i + j; };
            // Action<string> print = new Action<string> (delegate (string msg) { System.Console.WriteLine (msg); });
            Action<string> print = delegate (string msg) { System.Console.WriteLine (msg); };
            print (add (1, 2).ToString ());
        }

        private static void V3 ()
        {
            Func<int, int, int> add = (a, b) => a + b;
            Action<string> print = (msg) => System.Console.WriteLine(msg);
            print(add(1,2).ToString());
        }

        private static int Add (int a, int b) => a + b;
        private static void Print (string msg) => System.Console.WriteLine (msg);
    }
}